#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
#define ls (x<<1)
#define rs ((x<<1)|1)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=1e5+5;
int n,m;
int a[N],b[N],last[N];
struct node{
	int tag[4],cnt[1<<4];
}tree[N<<2];
void update(int x,int l,int r){
	fill(tree[x].cnt,tree[x].cnt+(1<<m),0);
	int S=0;
	for(int i=0;i<m;i++)
		if(tree[x].tag[i]>0)S|=(1<<i);
	if(l==r)return tree[x].cnt[S]=1,void();
	for(int i=0;i<(1<<m);i++)
		tree[x].cnt[i|S]+=tree[ls].cnt[i]+tree[rs].cnt[i];
	return;
}
void build(int x,int l,int r){
	if(l==r)return tree[x].cnt[0]=1,void();
	build(ls,l,mid),build(rs,mid+1,r);
	return update(x,l,r);
}
void add(int x,int l,int r,int L,int R,int val){
	if(val<0)return;
	if(L<=l&&r<=R)return tree[x].tag[val]++,update(x,l,r);
	if(L<=mid)add(ls,l,mid,L,R,val);
	if(R>mid)add(rs,mid+1,r,L,R,val);
	return update(x,l,r);
}
void del(int x,int l,int r,int L,int R,int val){
	if(val<0)return;
	if(L<=l&&r<=R)return tree[x].tag[val]--,update(x,l,r);
	if(L<=mid)del(ls,l,mid,L,R,val);
	if(R>mid)del(rs,mid+1,r,L,R,val);
	return update(x,l,r);
}
int ask(int x,int l,int r,int L,int R,int s){
	if(L<=l&&r<=R){
		int ans=0;
		for(int i=0;i<(1<<m);i++)
			if((i|s)==(1<<m)-1)
				ans+=tree[x].cnt[i];
		return ans;
	}
	for(int i=0;i<m;i++)
		if(tree[x].tag[i]>0)s|=(1<<i);
	if(R<=mid)return ask(ls,l,mid,L,R,s);
	else if(L>mid)return ask(rs,mid+1,r,L,R,s);
	else return ask(ls,l,mid,L,R,s)+ask(rs,mid+1,r,L,R,s);
}
signed main(){
	freopen("reporter.in","r",stdin);
	freopen("reporter.out","w",stdout);
	read(n,m);build(1,1,n);
	for(int i=1;i<=n;i++){
		read(a[i]);
		last[i]=b[a[i]];
		b[a[i]]=i;
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=0,k=i;j<=m&&k>0;j++,k=last[k])
			add(1,1,n,last[k]+1,k,j),
			del(1,1,n,last[k]+1,k,j-1);
		ans+=ask(1,1,n,1,i,0);
	}
	write(ans);
	return flush(),0;
}

